﻿using System.ComponentModel.Composition;
using Caliburn.Micro;
using IdeaBlade.Application.Framework.Core.ViewModel;

namespace WpfHarness.ViewModels
{
    [Export]
    public class CustomersViewModel : Screen, IDiscoverableViewModel
    {
        private readonly Repository _repository;

        private BindableCollection<Customer> _customers;

        [ImportingConstructor]
        public CustomersViewModel(Repository repository)
        {
            _repository = repository;
        }

        public BindableCollection<Customer> Customers
        {
            get { return _customers; }
            private set
            {
                _customers = value;
                NotifyOfPropertyChange(() => Customers);
            }
        }

        protected override void OnInitialize()
        {
            base.OnInitialize();
            _repository.GetCustomersAsync(results => Customers = new BindableCollection<Customer>(results));
        }
    }
}